$(function(){
			$(".fg-button")
			.hover(
				function(){ 
					$(this).addClass("ui-state-hover"); 
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			)
			.mousedown(function(){
					$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
					if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
					else { $(this).addClass("ui-state-active"); }	
			})
			.mouseup(function(){
				if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
					$(this).removeClass("ui-state-active");
					$(this).removeClass("ui-state-hover");
				}
			});
		});

function hydeElements()
{
	var fobj = document.getElementById("formc");
		var status = document.getElementById("statusID").value;
	var userType = document.getElementById("userTypeID").value;
	var enabledButtons = document.getElementById("enabledButtons").value;
	var permissionID = document.getElementById("permissionID").value;
	var pollID = document.getElementById("pollID").value;
	
	
	//Para el formulario PB leo los hidden_cell y segun el permiso los escondo o no
	
	if(!(userType == 'ROLE_SUPERVISOR' || userType == 'ROLE_REVISOR' || userType == 'ROLE_COORD' || userType == 'ROLE_USER_ADMIN'))
	{
		var classElems = getElementsByClassName('hidden_cell',null);
		var i = 0;
		while(i < classElems.length)
		{
			classElems[i].style.display = 'none';
			i++;
		}
	}
	
	//Leo los hidden_cell_always y escondo a todos
	
	var classElems = getElementsByClassName('hidden_cell_allways',null);
	var i = 0;
	while(i < classElems.length)
	{
		classElems[i].style.display = 'none';
		i++;
	}
	
	
	if(enabledButtons.length > 0)
	{
		var mySplitResult = enabledButtons.split("|");
		for(var i = 0;i < mySplitResult.length;i++)
		{
			var k = document.getElementById(mySplitResult[i]);
			k.style.display = 'inline';
		}
	}
	
	//El pollID 34 es el formulario L Regionalizado que siempre tiene que ser solo lectura.
	//Los pollID 35,36 y 37 son los de Estructura que siempre tiene que ser solo lectura.
	if ((permissionID == 1) || (pollID == 34 || pollID == 35 || pollID == 36 || pollID == 37))
//	if ((permissionID == 1))
	{
		for(var i = 0;i < fobj.elements.length;i++)
		{
			switch(fobj.elements[i].type)
		    {
		    	case "text":
	 	   			fobj.elements[i].readOnly = true;
	 	   			break; 
				case "textarea":
		    		fobj.elements[i].readOnly = true;
		    	   	break; 
		    	case "checkbox":
		    		fobj.elements[i].readOnly = true;
		    	   	break;
		    	case "select-one":
		    		fobj.elements[i].readOnly = true;
		    		break;  
			}
		}
		document.getElementById("rejectCommentsTA").readOnly = false;
	}
}

String.prototype.trim = function()
{
	return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
};

String.prototype.startsWith = function(str) 
{
	return (this.match("^"+str)==str);
};

String.prototype.endsWith = function(str) 
{
	return (this.match(str+"$")==str);
};

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function lockFieldsForm()
{
	var lockedList = document.getElementById("lockedList").value;
	if(lockedList.length > 0)
	{
		var mySplitResult = lockedList.split("|");
		for(var i = 0;i < mySplitResult.length;i++)
		{
			var k = document.getElementById(mySplitResult[i]);
			if(k!=null)
			{
				k.readOnly = true;
			}			
		}	
	}
}

function changeStatusByElements()
{	
	var formStatusID = document.getElementById("formStatusID").value;
    var elementID = document.getElementById("elementID").value;
    var pollStatusID = document.getElementById("pollStatusID").value;
    if(formStatusID != null && formStatusID.length > 0 && elementID != null && elementID.length > 0) 
	{
		changeFormStatus(formStatusID,elementID);
	}
	if(pollStatusID != null && pollStatusID.length > 0)
	{
		changePollStatus(pollStatusID);	
	}	
}

function changePollFormStatus(formStatusID,params,pollStatusID)
{
	changeFormStatus(formStatusID,params);
	changePollStatus(pollStatusID);
}

function changeFormStatus(formStatusID,params)
{
    if(formStatusID != null && formStatusID.length > 0 && params != null && params.length > 0)           
    {
    	if(params == "ALL")
    	{
    		var imgElements = top.main.document.getElementsByTagName('img');
    		for(var i = 0;i < imgElements.length;i++)
    		{
    			if(imgElements[i].id != 'companyStatusImg' && imgElements[i].id != 'validateStatusImg' 
    			&& imgElements[i].id != 'sendStatusImg' && imgElements[i].id != 'rejectStatusImg'
    			&& imgElements[i].id != 'approveStatusImg')
    			{
    	    		if(formStatusID == 2)
    	    		{
    	    			imgElements[i].src = "styles/img/gcircle.png";
    	    		}
    	    		if(formStatusID == 3)
    	    		{
    	    			imgElements[i].src = "styles/img/rcircle.png";
    	    		}
    	    		if(formStatusID == 4)
    	    		{
    	    			imgElements[i].src = "styles/img/validate_ok.gif";
    	    		}
    	    		if(formStatusID == 5)
    	    		{
    	    			imgElements[i].src = "styles/img/validate_error.gif";
    	    		}
    	    		if(formStatusID == 6)
    	    		{
    	    			imgElements[i].src = "styles/img/pending.png";
    	    		}
    	    		if(formStatusID == 7)
    	    		{
    	    			imgElements[i].src = "styles/img/accept.png";
    	    		}
    	    		if(formStatusID == 8)
    	    		{
    	    			imgElements[i].src = "styles/img/reject.png";
    	    		}
    			}
    		}
    	}
    	else
    	{
    		var menuItem = top.main.document.getElementById(params);
    		var menuItemContent = menuItem.innerHTML;
    		if(formStatusID == 2)
    		{			
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/gcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/gcircle.png\"");    			
    			
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 3)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/rcircle.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/rcircle.png\"");
    			
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 4)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/validate_ok.gif\"");
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 5)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/validate_error.gif\"");
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 6)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/pending.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/pending.png\"");
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 7)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/accept.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/accept.png\"");
    			menuItem.innerHTML = menuItemContent;
    		}
    		if(formStatusID == 8)
    		{
    			menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/rcircle.png\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_ok.gif\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/validate_error.gif\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/reject.png\"");
    			menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/reject.png\"");
    			menuItem.innerHTML = menuItemContent;
    		}
    	}
    }
}

function changePollStatus(pollStatusID)
{
	var menuItem = top.main.document.getElementById("companyTitle");
	var menuItemContent = menuItem.innerHTML;
	if(pollStatusID == 1)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/wcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/wcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/wcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/wcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/wcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/wcircle.png\"");
		menuItem.innerHTML = menuItemContent;
	}
	if(pollStatusID == 2)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/gcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/gcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/gcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/gcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/gcircle.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/gcircle.png\"");
		menuItem.innerHTML = menuItemContent;
	}
	if(pollStatusID == 3)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/pending.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/pending.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/pending.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/pending.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/pending.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/pending.png\"");
		menuItem.innerHTML = menuItemContent;
	}
	if(pollStatusID == 4)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/review.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/review.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/review.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/review.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/review.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/review.png\"");
		menuItem.innerHTML = menuItemContent;
	}
	if(pollStatusID == 5)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/reject.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/reject.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/reject.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/reject.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/reject.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/reject.png\"");		
		menuItem.innerHTML = menuItemContent;
	}
	if(pollStatusID == 6)
	{
		menuItemContent = menuItemContent.replace("src=\"styles/img/wcircle.png\"", "src=\"styles/img/accept.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/gcircle.png\"", "src=\"styles/img/accept.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/pending.png\"", "src=\"styles/img/accept.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/review.png\"", "src=\"styles/img/accept.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/accept.png\"", "src=\"styles/img/accept.png\"");
		menuItemContent = menuItemContent.replace("src=\"styles/img/reject.png\"", "src=\"styles/img/accept.png\"");
		menuItem.innerHTML = menuItemContent;
	}
}